<div class="project">
  <% project.stages_by_pay_status(pay_status).each do |stage| %>    
    <table width="100%">
      <tr>
          <td align="center">
            <h2>
              <%= project.name %>-阶段性-<%= t pay_status %>提成            
              <%= link_to '>>按设计师', 
                    print_one_project_url(:id => @project.id,
                      :type => 'desingers',
                      :pay_status => pay_status
                    ), 
                    :class => 'type' %>
            </h2>
          </td>
      </tr>
    </table>
    <table width="100%" >
      <tr>
        <td align="left">
          <h3><%= stage.name  %></h3>
        </td>
        <td align="right">
          <h3>日期:</h3>
        </td>
        <td width="100"></td>
      </tr>
    </table>
    <table width="100%" cellpadding="3" cellspacing="0"  class="work_items">
      <tr>
        <th>类别</th>
        <th>提成部分</th>
        <th>姓名</th>
        <th>报酬单位</th>
        <th>计费面积</th>
        <th>工作量</th>
        <th>发放比例</th>
        <th>指导比例</th>
        <th>类型系数</th>
        <th>修改系数</th>
        <th>难度系数</th>
        <th>应得金额</th>
        <th>小计金额</th>
      </tr>
      <% stage.work_item_types.each_with_index do |work_item_type, type_index| %>      
        <% stage.work_items_by_work_item_type_id(work_item_type.id).each_with_index do |work_item, work_item_index| %>
          <% work_item.designer_work_items_by_stage_id(stage.id).each_with_index do |designer_work_item,index| %>
        <%# stage.designers_by_work_item_type_id(work_item_type.id).each_with_index do |designer, designer_index|  %>
          <%# designer.designer_work_items_by(:stage_id => stage.id, :work_item_type_id => work_item_type.id).each_with_index do |designer_work_item,index|  %>
            <tr>
              <% if work_item_index == 0 and index == 0 %>
                <td align="center" rowspan="<%= work_item_type.designer_work_items_by_stage_id(stage.id).size %>">
                  <%= work_item_type.name %>                 
                </td>
              <% end %>
              <% if index == 0 %>
                <td align="center" rowspan="<%= work_item.designer_work_items.size %>">
                  <%= designer_work_item.try(:work_item).try(:name) %>
                </td>
              <% end %>
                <td align="center"><%= designer_work_item.designer.full_name %></td>
              <% if designer_work_item.try(:work_item).try(:allowance?) %>
                <% 8.times.each do  %>
                <td  align="center">--</td>
                <% end %>
              <% else %>
                <td align="right"><%= designer_work_item.try(:work_item).try(:pay_unit) %></td>
                <td align="right"><%= designer_work_item.billing_area %></td>
                <td align="right"><%= designer_work_item.work_load %> %</td>
                <td align="right"><%= designer_work_item.provided_percent %> %</td>
                <td align="right"><%= designer_work_item.guided_percent %> %</td>
                <td align="right"><%= designer_work_item.type_num %> %</td>
                <td align="right"><%= designer_work_item.motify_num %> %</td>
                <td align="right"><%= designer_work_item.difficulty_num %> %</td>
              <% end %>
              <td align="right"><%= number_with_precision designer_work_item.should_be_payed, :precision => 1 %></td>
              <% if index == 0 %>
              <td rowspan="<%= work_item.designer_work_items.size %>" align="right">
                <%= number_with_precision designer_work_item.work_item.should_be_payed, :precision => 1 %>                
              </td>
              <% end %>
            </tr>
          <% end %>
        <% end if work_item_type.designer_work_items_by_stage_id(stage.id).any? %>
      <% end %>
      <tr>
        <td colspan="11">合计:</td>
        <td colspan='2' align="right">
          <%#= project.payed_by_pay_status(pay_status) %>
          <%= number_with_precision stage.should_be_payed, :precision => 1 %>
        </td>
      </tr>
    </table>
    <table width="100%" >
      <tr>
        <td align="left">
          <h3>审批:</h3>
        </td>
        <td align="center">
          <h3>审核:</h3>
        </td>
        <td align="right">
          <h3>制表:</h3>
        </td>
        <td width="100"></td>
      </tr>
    </table>
    <div class="next_page"></div>
  <% end %>  
</div>